package com.yanqingying.controller;

import com.yanqingying.aop.log;
import com.yanqingying.*;
import com.yanqingying.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class EmpController {
    @Autowired
    EmpService empService;

    @GetMapping("/emps")
    public Result page(EmpQueryParam param) {
        log.info("分页查询");
        PageBean pageBean = empService.page(param);
        return Result.success(pageBean);
    }

    @PostMapping("/emps")
    public Result add(@RequestBody Emp emp) {
        log.info("加入员工");
        empService.add(emp);
        return Result.success();
    }
    @log
    @DeleteMapping("/emps")
    public Result del(@RequestParam List<Integer> ids) {
        log.info("ids" + ids);
        empService.delete(ids);
        return Result.success();
    }

    @GetMapping("/emps/{id}")
    public Result getsId(@PathVariable Integer id){
        Emp a = empService.getsId(id);
        return Result.success(a);
    }
    @log
    @PutMapping("/emps")
    public Result upDate(@RequestBody Emp id){
        log.info("id"+id);
        empService.upDate(id);
        return Result.success();
    }
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        LoginInfo info = empService.login(emp);
        if (info != null ){
            return Result.success(info);
        }
        return Result.error("请输入正确用户名和密码");
    }
}